350C - Bombs - CodeForces Solution


greedy implementation sortings *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;


//#define ONLINE_JUDGE
#define iloop(n)    for(int i=0;i<n;i++)
#define jloop(n)    for(int j=0;j<n;j++)
#define all(x)      x.begin(),x.end()



typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
typedef std::pair<long, long> pll;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<pii> vpii;
typedef std::vector<vector<pair<int, int>>> vvpii;
typedef std::vector<vector<ll>> vvll;
typedef std::vector<ll> vll;
typedef std::vector<vector<char>> vvc;
typedef std::vector<char> vc;

ll mod = (1e9)+7;

template<class T>
void get(vector<T>& a){int n=a.size(); iloop(n) {cin>>a[i];}}

template<class T>void out(vector<T>& a){for(T e:a) cout<<e<<' ';cout<<'\n';}


bool check(pii& p1, pii& p2)
{
   return abs(p1.first)+abs(p1.second) < abs(p2.first)+abs(p2.second);
}

void get_dialogue(int mode, int x)
{
    if(x==0) return;
    //horizontal
    if(mode==1)
    {
        if(x<0)
        {
            cout<<"1 "<<-x<<" L"<<'\n';
        }
        else
        {
            cout<<"1 "<<x<<" R"<<'\n';
        }
    }
    else
    {
        if(x<0)
        {
            cout<<"1 "<<-x<<" D"<<'\n';
        }
        else
        {
            cout<<"1 "<<x<<" U"<<'\n';
        }
    }
}
int main() 
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    vpii a(n);
   
    for(int i=0;i<n;i++)
    {
        int x, y; cin>>x>>y;
        a[i].first=x;
        a[i].second=y;
    }
    sort(all(a), check);
    int cnt=0;

    for(auto p:a)
    {
        if(p.first!=0) cnt+=2;
        if(p.second!=0) cnt+=2;
        cnt+=2;
    }
    cout<<cnt<<'\n';
    for(auto p:a)
    {
       // cout<<"point: "<<p.first<<' '<<p.second<<'\n';
        get_dialogue(1, p.first);
        get_dialogue(2, p.second);
        cout<<"2\n";
        get_dialogue(2, -p.second);
        get_dialogue(1, -p.first);
        cout<<"3\n";
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits